Ext.ns('SearchBroker');
SearchBroker.ChartPanel = Ext.extend(Ext.Panel, {
	//renderTo: 'binding-example',
	frame: true,
	title: 'SearchBroker List',
	//width: 540,
	//height: 400,
	layout: 'border',
	initComponent :function(){
	   this.items = [
	     	   		{
	    				id: 'urlPanel',
	    				region: 'north',
	    				bodyStyle: {
	    					background: '#ffffff',
	    					padding: '7px'
	    				},
	    				html: '<a>url........</a>'
	    			},
	    			SearchBroker.DataPanel
	    		],
	   Ext.Panel.superclass.initComponent.apply(this, arguments);  
	   Ext.getCmp("HelpMsg").setValue("Broker request:" +
			   "-1,7,45,1,1,1555\n类型为FIRM(1)SearchID为1555\n\n" +
			   "Special Request:");
			   
	}
});
SearchBroker.tbar = [ 'SearchType: ',' '
                      ,new Ext.form.ComboBox({
                    	  id:'SearchType',
                    	  hiddenName:'SearchType',
                          store: [['0','BROKER'],['1','FIRM']],
                          typeAhead: true,
                          forceSelection: true,
                          triggerAction: 'all',
                          valueField:'value',
                          displayField :'key',
                          width:120,
                          emptyText:'Select a type...',
                          selectOnFocus:true
                      })
                     ," "," ",
               'SearchIDs: ','',
    		   {
    			   id:'SearchIDs',
    			xtype:'field',
    				width:60,
    				listeners : {  
                        specialKey : function(field, e) {  
                            if (e.getKey() == Ext.EventObject.ENTER) {
                            	SearchBroker.requestHandler();   
                            }  
                        } 
    				}
    		   },
    		   " "," ",
               'filterID: ','',
    		   {
    			   id:'filterID',
    			xtype:'field',
    				width:60,
    				listeners : {  
                        specialKey : function(field, e) {  
                            if (e.getKey() == Ext.EventObject.ENTER) {
                            	SearchBroker.requestHandler();   
                            }  
                        } 
    				}
    		   },
    		   " "," ",
               'ASKBIDLimit: ','',
    		   {
    			   id:'ASKBIDLimit',
    			xtype:'field',
    				width:60,
    				listeners : {  
                        specialKey : function(field, e) {  
                            if (e.getKey() == Ext.EventObject.ENTER) {
                            	SearchBroker.requestHandler();   
                            }  
                        } 
    				}
    		   },
               " "," "
        		    ,'-',
                  {
                  	xtype:'button',
                  	text:'Search',
                  	handler: function(){
    			   		SearchBroker.requestHandler();
        		    }
                  }
        ];
SearchBroker.DataPanel =  new Ext.Panel({	
	//renderTo: document.body,
	region: 'center',
	//autoHeight: true,
    //autoWidth:true,
    autoScroll: true,
	
	title : 'Search Broker',
	tbar:SearchBroker.tbar,
	layout:"border", 
	items:[
	{	id:'headerfield',
		region:"north",
		xtype:"field",
		fieldLabel:"headerfield:",
		name:"headerfield",
		value:"request......",
		height:25,
		readOnly : true,
		width:800},
		{	id:'resultMsg',
			xtype:"textarea",
            fieldLabel:"result:",
            region:"center",
            name:"resultMsg",
            height:450,
			readOnly : true,
			width:800},
			{	id:'HelpMsg',
				xtype:"textarea",
	            fieldLabel:"result:",
	            region:"east",
	            name:"HelpMsg",
	            height:450,
				readOnly : true,
				width:200}
	]
});
SearchBroker.requestHandler = function requestHandler() {	
	var urls =contextURL+'SearchBrokerServlet';
	var fieldid = Ext.getCmp("SearchType").getValue();
	var code = Ext.get("SearchIDs").dom.value;
	var filterID = Ext.getCmp("filterID").getValue();
	var limit = Ext.getCmp("ASKBIDLimit").getValue();
	
	if(fieldid==""){
		 Ext.Msg.alert("提示信息","SearchType is not null!"); 
		return;
	}
	if(code==""){
		 Ext.Msg.alert("提示信息","SearchIDs is not null!"); 
		return;
	}
	urls = urls+"?searchType="+fieldid+"&searchIDs="+code+"&filterID="+filterID+"&limit="+limit;
	 
	Ext.getDom("urlPanel").innerHTML = "<a href='" + urls + "' target='_blank'>" + urls + "</a>";
	var mk = new Ext.LoadMask(Ext.getBody(), {
		msg: '正在更新数据，请稍候！'
	});
	mk.show(); //显示
	
	
	Ext.Ajax.request( {
		url : urls,
		method : "GET",
		success : function(result, request) {
			var jsonResult = Ext.util.JSON.decode(result.responseText);
			if (jsonResult.resultCode=='0'){				
				Ext.getCmp("headerfield").setValue("request:"+jsonResult.reqStr);
				Ext.getCmp("resultMsg").setValue("Hearder:\n"+jsonResult.header+"\nContent:\n"+jsonResult.content);
			}
			else
			{
				Ext.Msg.alert('操作提示','结果为空'); 
			}
			mk.hide();
			Ext.getCmp("SearchIDs").focus();
		
		},
		failure : function(result, request) {
			Ext.MessageBox.alert('访问失败', '失败了就没好说的了  (*^__^*) 嘻嘻……: ');
			mk.hide();
			Ext.getCmp("SearchIDs").focus();
		}
			// ,scope : this
			// params: param
		});
};
Ext.onReady(function(){
	//War.ChartGrid.render(document.body);
	new SearchBroker.ChartPanel({
		frame: true,
		layout:'border',
		renderTo: 'grid-example',
		height : 600,
		width : 1000
	});
});
	
